package com.marvels.loanapply.loan.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.marvels.common.constants.MarvelsConstant;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.utils.CacheUtils;
import com.marvels.loanapply.loan.dao.IStateDetailedDao;
import com.marvels.loanapply.loan.dto.StateDetailedDTO;
import com.marvels.loanapply.loan.service.IStateDetailedService;
@Service
public class StateDetailedServiceImpl implements IStateDetailedService {
	@Autowired
	private IStateDetailedDao stateDetailedDao;
	@Override
	public StateDetailedDTO findStateDetailedByNodeCode(String nodeCode) throws MarvelsBusinessException{
		// 条件查询
		StateDetailedDTO stateDetailed = new StateDetailedDTO();
		if(nodeCode==null) {
			throw new MarvelsBusinessException("流程节点不能为空");
		}
		stateDetailed.setNodeCode(nodeCode);
		List<StateDetailedDTO> sds =  stateDetailedDao.selectStateDetailed(stateDetailed);
		if(sds==null || sds.size() !=1) {
			throw new MarvelsBusinessException(nodeCode+"查询出来的状态数量不正确state_num:"+sds);
		}
		return sds.get(0);
	}
	
	
	/**
	 * 查询流程状态
	 * @param dto
	 * @return
	 * @throws MarvelsBusinessException
	 */
	public List<StateDetailedDTO> findStateDetailed(StateDetailedDTO  dto) throws MarvelsBusinessException{
		/*Object object=CacheUtils.getCacheObject(MarvelsConstant.PROCESS_STATUS_LIST);
		List<StateDetailedDTO> list=null;
		if(object==null){
			// 条件查询
			list = stateDetailedDao.selectStateDetailed(dto);
			CacheUtils.cacheObject(MarvelsConstant.PROCESS_STATUS_LIST, list);
		}else{
			list=(List<StateDetailedDTO>)object;
			
		}*/
		return stateDetailedDao.selectStateDetailed(dto);
	}
}
